package com.stone.jvm;

import java.util.ArrayList;
import java.util.List;

/**
 * 栈上分配测试
 * -Xmx1G -Xms1G -XX:-DoEscapeAnalysis -XX:+PrintGCDetails
 */
public class StackAllocationTest {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            test();
        }
        long end = System.currentTimeMillis();
        System.out.println("花费的时间为 : " + (end - start) + " ms");
        try {
            Thread.sleep(10000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * 当前方法内的变量没有发生逃逸分析
     */
    public static void test() {
        List list = new ArrayList();
    }
}
